import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      // {
      //   path: 'index',
      //   component: () => import('@/views/profile'),
      //   name: 'Profile',
      //   meta: { title: '个人中心', icon: 'user', noCache: true }
      // },
      {
        path: 'update-psd',
        component: () => import('@/views/profile/update-psd'),
        name: 'updatePsd',
        meta: { title: '修改密码', noCache: true }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard'),
        name: 'dashboard',
        meta: {
          title: '控制台主页',
          icon: 'icon-dashboard',
          affix: true
        }
      }
    ]
  }
]
// const modulesFiles = require.context("./modules", false, /\.js$/); // 导入整体模块 无需额外引入
// modulesFiles.keys().map(path => {
//   // 兼容处理：.default 获取 ES6 规范暴露的内容; 后者获取 commonJS 规范暴露的内容
//   constantRoutes.push(modulesFiles(path).default || modulesFiles(path));
// });
Vue.use(Router)

// let base = `${process.env.BASE_URL}` // 动态获取二级目录
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    // base: base,
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  })

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

const router = createRouter()
export default router
